import {
	getAllShowNews,
	getAllShowFinancialInformation,
	getAllShowAnnouncement,
	updateAnnouncementStatusById,
	getAnnouncement,
	getAnnouncementByAnnouncementStatus,
	getMessageListByStatus,
	getMessageListByUserId,
	updateAllAnnouncementStatus
} from '../../..//http/message/message.js'


export default ({
	namespaced: true,
	state: {
		showNews: [], //展示新闻
		showFinancialInformation:[],//展示财经咨询新闻
		xitongtells:[],//系统公告
		xitongTime:"",//接受到公告的时间
	},
	mutations: {
		getShowNews(state, a) {
			state.showNews = a
		},
		showFinancialInformationmutations(state,a){
			state.showFinancialInformation=a
		},
		getxitongtells(state,a){
			state.xitongtells=a
		},
		getxitongTime(state,a){
			state.xitongTime=a
		},
	},
	actions: {
		//查询状态为展示的新闻信息集合
		async getAllShowNews(context, a) {
			const data = await getAllShowNews()
			if (data.code == 10001) {
				context.commit("getShowNews", data.data)
				
			}
		},
		//查询状态为展示的理财咨询信息集合
		async getAllShowFinancialInformation(context, a) {
			const data = await getAllShowFinancialInformation()
			if (data.code == 10001) {
				context.commit("showFinancialInformationmutations", data.data)
				
			}
		},
		//查询状态为展示的系统公告集合
		async getAllShowAnnouncement(context, announcementStatus) {
			const data = await getAllShowAnnouncement(announcementStatus)
			if (data.code == 10001) {
				context.commit("getxitongtells", data.data)
				console.log("888",data)
				if(data.data.length>0){
					let date = new Date(data.data[data.data.length-1].announcementCreateTime);
					//时间戳为10位需*1000，时间戳为13位的话不需乘1000
					        let y = date.getFullYear();
					        let MM = date.getMonth() + 1;
					        MM = MM < 10 ? ('0' + MM) : MM;//月补0
					        let d = date.getDate();
					        d = d < 10 ? ('0' + d) : d;//天补0
					        let h = date.getHours();
					        h = h < 10 ? ('0' + h) : h;//小时补0
					        let m = date.getMinutes();
					        m = m < 10 ? ('0' + m) : m;//分钟补0
					        let s = date.getSeconds();
					        s = s < 10 ? ('0' + s) : s;//秒补0
					        let timer=  h + ':' + m;
									//console.log(data.data[data.data.length-1].announcementCreateTime)
					    context.commit("getxitongTime",timer)
				}
				
			}
		},
		//修改系统公告状态为已读
		async updateAnnouncementStatusById(context, announcementId) {
			return await updateAnnouncementStatusById(announcementId)
		},
		//查询状态为所有的系统公告集合
		async getAnnouncement(context, announcementStatus) {
			return await getAnnouncement()
		},
		//修改所有系统公告为未读状态(测试)
		async getAnnouncementByAnnouncementStatus(context, announcementStatus) {
			return await getAnnouncementByAnnouncementStatus()
		},
		//根据用户id和消息状态查询该用户收到的系统消息集合
		async getMessageListByStatus(context, messageStatus) {
			return await getMessageListByStatus(messageStatus)
		},
		////根据userId查询用户收到的通知消息
		async getMessageListByUserId(context, messageStatus) {
			return await getMessageListByUserId()
		},
		//////修改所有通知消息为已读状态
		async updateAllAnnouncementStatus(context, messageStatus) {
			return await updateAllAnnouncementStatus()
		},
	},


})
